home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / CHMOD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  708 b   |  29 lines

  1. /* chmod.c, from page 351 of Turbo C Bible */
  2. #include<stdio.h>
  3. #include<sys\types.h>
  4. #include<sys\stat.h>
  5. #include<io.h>
  6. main (int argc, char **argv)
  7. {
  8.    int pmode = -999;
  9.    if (argc < 3)
  10.    {
  11.         printf (
  12.           "Usage: %s <pathname> <R|W>\n", argv [0]);
  13.    }
  14.    else
  15.    {
  16.                    /* Convert last argument to permission code */
  17.     if (argv [2] [0] == 'R') pmode = S_IREAD;
  18.     if (argv [2] [0] == 'W') pmode = S_IREAD|S_IWRITE;
  19.         if (pmode == -999)
  20.         {
  21.              printf ("Unknown permission: %s\n", argv [2]);
  22.              exit (1);
  23.         }
  24.         if (chmod (argv [1], pmode) == -1)
  25.         {
  26.              perror ("Error in \"chmod\"");
  27.         }
  28.    }
  29. }